package com.yinhe.system.service.impl;

import java.util.List;

import com.yinhe.common.annotation.DataScope;
import com.yinhe.common.exception.ServiceException;
import com.yinhe.common.utils.DateUtils;
import com.yinhe.common.utils.StringUtils;
import com.yinhe.common.utils.bean.BeanValidators;
import com.yinhe.system.domain.YhRiskProject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.yinhe.system.mapper.YhSecurityworkMapper;
import com.yinhe.system.domain.YhSecuritywork;
import com.yinhe.system.service.IYhSecurityworkService;
import springfox.documentation.oas.mappers.SecurityMapper;

import javax.validation.Validator;

/**
 * 保卫工作Service业务层处理
 * 
 * @author yinhe
 * @date 2022-07-20
 */
@Service
public class YhSecurityworkServiceImpl implements IYhSecurityworkService {
    @Autowired
    private YhSecurityworkMapper yhSecurityworkMapper;
    @Autowired
    protected Validator validator;
    private static final Logger log = LoggerFactory.getLogger(SysUserServiceImpl.class);

    /**
     * 查询保卫工作
     *
     * @param id 保卫工作主键
     * @return 保卫工作
     */
    @Override
    public YhSecuritywork selectYhSecurityworkById(Long id) {
        return yhSecurityworkMapper.selectYhSecurityworkById(id);
    }

    /**
     * 查询保卫工作列表
     *
     * @param yhSecuritywork 保卫工作
     * @return 保卫工作
     */
    @Override
    @DataScope(deptAlias = "c", userAlias = "c")
    public List<YhSecuritywork> selectYhSecurityworkList(YhSecuritywork yhSecuritywork) {
        return yhSecurityworkMapper.selectYhSecurityworkList(yhSecuritywork);
    }

    /**
     * 新增保卫工作
     *
     * @param yhSecuritywork 保卫工作
     * @return 结果
     */
    @Override
    public int insertYhSecuritywork(YhSecuritywork yhSecuritywork) {
        yhSecuritywork.setCreateTime(DateUtils.getNowDate());
        return yhSecurityworkMapper.insertYhSecuritywork(yhSecuritywork);
    }

    /**
     * 修改保卫工作
     *
     * @param yhSecuritywork 保卫工作
     * @return 结果
     */
    @Override
    public int updateYhSecuritywork(YhSecuritywork yhSecuritywork) {
        yhSecuritywork.setUpdateTime(DateUtils.getNowDate());
        return yhSecurityworkMapper.updateYhSecuritywork(yhSecuritywork);
    }

    /**
     * 批量删除保卫工作
     *
     * @param ids 需要删除的保卫工作主键
     * @return 结果
     */
    @Override
    public int deleteYhSecurityworkByIds(Long[] ids) {
        return yhSecurityworkMapper.deleteYhSecurityworkByIds(ids);
    }

    /**
     * 删除保卫工作信息
     *
     * @param id 保卫工作主键
     * @return 结果
     */
    @Override
    public int deleteYhSecurityworkById(Long id) {
        return yhSecurityworkMapper.deleteYhSecurityworkById(id);
    }

    /**
     * 导入项目风险数据
     */
    @Override
    public String importSecuritywork(List<YhSecuritywork> SecurityworkList, Boolean isUpdateSupport) {
        int successNum = 0;
        StringBuilder successMsg = new StringBuilder();
        StringBuilder failureMsg = new StringBuilder();
        for (YhSecuritywork Securitywork : SecurityworkList) {
            this.insertYhSecuritywork(Securitywork);
            successNum++;
            /*successMsg.append("<br/>" + successNum + " 导入成功");*/

        }
        successMsg.insert(0, "恭喜您，数据已全部导入成功！共 " + successNum + " 条");
        return successMsg.toString();
    }
}